﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VirtualMarketParameters.cs" company="">
//   
// </copyright>
// <summary>
//   The virtual market parameters.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using Systemathics.FrameWork;

namespace Systemathics.Providers
{
    internal sealed class VirtualMarket
    {
        private static double hitorTakeProbability;
        private static double minimumHitRatioProbability;
        private static double rejectionProbability;
        private readonly Random random = new Random((int) Time.Now.Ticks);

        public VirtualMarket(VirtualMarketParameters vmp)
        {
            AckDelay = vmp.AckDelay;
            RejectionProbability = vmp.RejectionProbability;
            MinimumHitRatioProbability = vmp.MinimumHitRatioProbability;
            hitorTakeProbability = vmp.HITorTAKEProbability;
        }

        public int AckDelay { get; private set; }
        public double RejectionProbability { get; private set; }
        public double MinimumHitRatioProbability { get; private set; }
        public double HITorTAKEProbability { get; private set; }

        public bool NotRejected()
        {
            return (random.NextDouble() > rejectionProbability) ? true : false;
        }
        public bool HitorTake()
        {
            return (random.NextDouble() < hitorTakeProbability) ? true : false;
        }
        public double HitRatio()
        {
            // mu = (100% - MinimumHitRatioProbability)/2;
            // Max Sigma must not be lower than 0 and higher than 1
            // so  mu + 2.96 * Sigma  < 1  ;  99.9%
            // and mu - 2.96 * Sigma > 0.01;  0.1%
            if(random.NextDouble() > 0.2) 
                return 1;
            return ((double) random.Next((int) (minimumHitRatioProbability*100), 100))/100;
        }
    }
}